
import { View, Image } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import Taro from '@tarojs/taro'
import mbti from '../../assets/mbti.png'
import GlobalFooter from '../../components/GlobalFooter'
import quesitons from '../../data/questions.json'
import questionResults from '../../data/question_results.json'
import { getBestQuestionResult } from '../../utils/bizUtils'
import './index.scss'

export default () => {
  // 接受结果
  const answerList = Taro.getStorageSync('answerList');
  if(!answerList || answerList.length < 1){
    Taro.showToast({
      title:'答案为空，请先答题',
      icon:"error",
      duration:2000,
    });
  }

  // 根据答题算法进行性格判断
  const result = getBestQuestionResult(answerList, quesitons,questionResults);

    return <View className='resultPage'>
    <View className='at-article__h1 title'>{result.resultName}</View>
    <View className='at-article__h2 subTitle'>{result.resultDesc}</View>
    <AtButton type='primary' circle className='enterBtn' onClick={()=>{
      Taro.reLaunch({
        url:'/pages/index/index'
      })
    }}>返回主页</AtButton>
    <Image src={mbti} className='headerBg'/>
    <GlobalFooter/>
  </View>
};
